﻿using Nancy.Hosting.Self;
using RinNote.Server.Log;
using RinNote.Server.Model;
using RinNote.Server.Module;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RinNote.Server
{
    class Program
    {
        static void Main(string[] args)
        {
            //using (RinNoteContext entity = new RinNoteContext())
            //{
            //    var user = entity.account.Where(i => i.AccountID == "1").FirstOrDefault();
            //    if (user == null)
            //    {
            //        entity.account.Add(new Account() { AccountID = "1", Password = "admin", UserName = "admin", Role = AccountRole.ADMIN });
            //        entity.SaveChanges();
            //    }
            //}
            //NoteModule nm = new NoteModule();
            //var fid = NoteModule.CreateFolders(new Account() { AccountID = "1", Password = "admin", UserName = "admin", Role = AccountRole.ADMIN },
            //    new Model.FileModel.Folder() { _id = "test2", FolderName = "test2", CreateUserId = "1", HasPassword = false });
            //var folders= NoteModule.GetFoldersFromParentFolderId(new Account() { AccountID = "1", Password = "admin", UserName = "admin", Role = AccountRole.ADMIN }, "");

            #region 初始化文件夹
            if (!Directory.Exists("NoteDB"))
            {
                Directory.CreateDirectory("NoteDB");
            }
            if (!Directory.Exists("Config"))
            {
                Directory.CreateDirectory("Config");
            }
            #endregion

            #region 启动Nancy
            StartApi("http://localhost:2121");
            #endregion
            Console.ReadLine();
        }
        static void StartApi(string Url)
        {
            var host = new NancyHost(new Uri(Url));
            host.Start();
            LogHelper.Message($"WebApi Running on {Url}", "Nancy", ConsoleColor.Red, ConsoleColor.White);
        }
    }
}
